/*//////////////////////////
///////20120204/////////
/////Shim sang woo/////
////////G-sensor/////////
*///////////////////////////

package com.example.ddakji;

import java.io.IOException;

import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback{


	private SurfaceHolder mHolder;
	private Camera camera = null;
	
	@SuppressWarnings("deprecation")
	public CameraSurfaceView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		
		mHolder = getHolder();
		mHolder.addCallback(this);
		mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		camera = Camera.open();
		
		try {
			camera.setPreviewDisplay(mHolder);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
		// TODO Auto-generated method stub
		camera.startPreview();
	}
	
	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		camera.stopPreview();
		camera = null;
	}
	
	public boolean capture(Camera.PictureCallback handler){
		if(camera !=null){
			camera.takePicture(null, null, handler);
			return true;
		}else{
			return false;
		}
	}
}